<?php

if(stristr($_SERVER['PHP_SELF'],".inc.php")) { 
	header("Location:index.php"); 
	exit; 
}

/* if(!function_exists('mime_content_type')) {
   function mime_content_type ($f) {
       return system(trim('file -bi '.escapeshellarg($f))) ;
   }
} */

$uploaddir 		= $svrRoot."uploads/"; 
$uploadfiles 	= glob("$uploaddir{*}", GLOB_BRACE);
if(is_array($uploadfiles)) { 
	$trimmed=0; 
	$usize = sizeof($uploadfiles); 
	if($usize > 5) {
		$trimmed=1; 
		if(!$_GET['offset']) { 
			$o = 0; 
		} else { 
			$o=intval($_GET['offset']); 
		}
		$uploadfiles = array_slice($uploadfiles,$o,'10');
	}
	$i=0; 
	
	echo "<div id=\"uploadcontents\">";
	foreach($uploadfiles as $k=>$v) { 
		//if(stristr(mime_content_type($v),"image/")) { 
			$fname = str_replace($uploaddir,"",$v);
			list($width, $height, $type, $attr) = getimagesize($v);
			if($width>$height) { $style="width:200px;"; } else { $style="height:200px;"; } 
			echo "<div class=\"uploaditem\">
			<img src=\"".$publicURL."uploads/".$fname."\" style=\"$style\" alt=\"".htmlspecialchars($fname)
			. "\" align=\"middle\" /><br />"
			. "<b>Image Properties: ". $attr."<br />";
			if(function_exists('exif_read_data')) { 
				echo "<fieldset class=\"collapsedfieldset\"><legend><a href=\"javascript:toggleEXIF('".$k."')\">"
				. "EXIF Data</a></legend><div id=\"exif_".$k."\" style=\"padding:5px;display:none;\">";
				if($exif = @exif_read_data($v, 0, true)) { 
					if(is_array($exif)) { 
						foreach ($exif as $key => $section) {
							foreach ($section as $name => $val) {
								echo "$key.$name: $val<br />\n";
							}
						}
					}
				} else { 
					echo "No EXIF data available to read!"; 
				}
				echo "</div></fieldset>";
			}
			echo "<input type=\"text\" class=\"text_input_small\" style=\"width:450px;\" value=\"&lt;img src=&quot;"
			. $publicURL."uploads/".$fname."&quot; alt=&quot;".htmlspecialchars($fname)."&quot; /&gt;\" /></div>";
			$i++; 
		//} else { 
		//	echo str_replace($uploaddir,"",$v)."<br />";
		//}
	}
    if($trimmed) { 
	   echo "<br /><br />";
	    if($trimmed && ($o > 0)) { echo "<a href=\"javascript:showUploads('".($o-5)."');\">&lt;&lt; Previous</a>"; }  
        if($trimmed && (($i+$o) < $usize)) { echo "&nbsp;&nbsp;<a href=\"javascript:showUploads('".($i+$o)."');\">Next &gt;&gt; </a>"; }
    }
	echo "</div>";
} else { 
	echo "There is nothing in your uploads directory!"; 
}
?>